#include <iostream>
#include <signal.h>
#include <unistd.h>

using namespace std;

void count(int n)
{
    while(n--)
    {
        printf("cnt: %2d",n);
        fflush(stdout);
        sleep(1);
        printf("\r");
    }
}

void handle(int signo)
{
    cout << "get a signo: " << signo << endl;
    count(20);
}

int main()
{
    struct sigaction act, oact;
    act.sa_handler = handle;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, 3);
    sigaction(SIGINT, &act, &oact);

    int cnt = 10;
    while(cnt--)
    {
        sleep(1);
    }
    return 0;
}